
//init state
const state = () => ({
  UserMsg: {
    logStatus: false
  }
})

//getters
const getters = {
  getUserId(state){
    return state.UserMsg.userid;
  }
}

//actions
const actions = {
  addMsg({commit},payload){
    commit("addMsgMut",payload);
  },
  updateLogStatus({commit},payload){//修改用户登录状态
    commit("updateLogStatusMut",payload);
  },
  clearData({commit}){//清空数据
    commit("clearDataMut")
  }
}

//mutations
const mutations = {
  addMsgMut(state,val){
    //为了响应式，才这样赋值
    state.UserMsg = {...state.UserMsg,...val};
  },
  updateLogStatusMut(state,val){//修改用户登录状态
    state.UserMsg.logStatus = val;
  },
  clearDataMut(state){//清空数据
    state.UserMsg = {...{logStatus: false}};
  }
}

export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations
}
